package com.atguigu.gmall.task.scheduled;

import com.atguigu.gmall.common.constant.MqConst;
import com.atguigu.gmall.common.service.RabbitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author atguigu-mqx
 */
//  定时任务：
@Component
@EnableScheduling   //  表示开启定时任务！
public class ScheduledTask {

    @Autowired
    private RabbitService rabbitService;
    //  如何使用！
    //  表示每隔10秒 执行一次！ 每天深夜1点钟，发消息！
    @Scheduled(cron = "0/10 * * * * ?")
    public void testTask(){
        //  System.out.println("人来的挺多.....服务不周请多担待...");
        this.rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_1,"来活了...准备吧！");
    }

    @Scheduled(cron = "0/40 * * * * ?")
    public void delData(){
        //  System.out.println("人来的挺多.....服务不周请多担待...");
        this.rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_18,"客人走了，出来吧...！");
    }
}
